package com.zsrt.java.day20161229.cg.homework.game.shuzi;

import java.io.Closeable;
import java.util.Scanner;
public class Play {
   public static void start(){
	   	Scanner sc = new Scanner(System.in);
	   	System.out.println("输入玩家名字");
	   	String name = sc.next();
	   	
	   	System.out.println("输入玩家密码");
	   	String psw = sc.next();
	
	   	if("chengao".equals(name)&&"123".equals(psw)){
	   		
			boolean con =true;
			while(con){
				wanFa(selectShu());
				System.out.println("是否继续(y/n)");
				con = sc.next().equalsIgnoreCase("y")?true:false;//这个好用！
			}
			System.out.println("game over");
	   	}
	   	System.out.println("用户名或者密码错误，请重新登陆");
	   	sc.close();
		
		
	}


	/**
	 * 将键入的数的每一个数位取出来然后放入一个数组
	 * @param shu
	 * @return
	 */
	public static int[] selectShu(){
		System.out.println("请输入一个三位数");
		Scanner input = new Scanner(System.in);
   		int shu = input.nextInt();
//   		这个问题我还是没有解决 它是写在方法内的扫描，而且参与
//			了循环，我一关闭它就报错，看看怎么解决？
//   		input.close();

   		
		int[] s = new int[3];
		for(int i=0;i<s.length;i++){
			s[0] = shu/100;
			s[1] = shu%100/10;
			s[2] = shu%10;			
		}
		return s;
	}
	public static void wanFa(int[] s){
		int len = s.length;
		int fg = s[len-1]%4;
		int result = 0;
		String f=null ;
		switch(fg){
		case 0: result = s[0]+s[1]+s[2];
				f = "+";
				break;
		case 1: result = s[0]-s[1]-s[2]; 
				f = "-";
				break;
		case 2: result = s[0]*s[1]*s[2]; 
				f = "*";
				break;
		case 3: result = s[0]/s[1]/s[2]; 
				f = "/";
				break;
		}
		for(int index=0;index<s.length;index++){
			if(index<s.length-1){
				System.out.print(s[index]+", ");				
			}else{
				System.out.print(s[index]);
			}
		}
		System.out.println("结果="+result+"\t"+"算法为:"+f+"\t"+"方法为："+s[0]+f+s[1]+f+s[2]);
	}
	
	public static void main(String[] args) {
		
			start();
			
		
	}
}
